package com.rudolfheszele.smsselector;

import com.rudolfheszele.smsselector.controller.Controller;
import com.rudolfheszele.smsselector.controller.ControllerFactoryFactory;
import com.rudolfheszele.smsselector.view.View;

import android.app.Activity;
import android.os.Bundle;

/**
 * This class is the starting Activity of the application
 * @author Rudolf Heszele
 * @version 0.1
 */
public class SmsSelectorMainActivity extends Activity implements View 
{
    /**
     * Called when the activity is first created.
     * @param savedInstanceState The variable where the possible early state can be fetched from
     * */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.smsselector_main_activity_layout);
        // The factory is initialized in the application's onCreate() method
        mController = ControllerFactoryFactory.getControllerFactory().getController();
        mController.registerView(this);
        if(savedInstanceState != null)
        	mController.restoreState(getId(), savedInstanceState);
    }
    
    @Override
    public void onResume()
    {
    	super.onResume();
    	mController.updateView(this);
    }
    
    /**
     * Called just before the activity will be killed.
     * @param outState The variable the state will be saved to
     */
    @Override
    public void onSaveInstanceState(Bundle outState)
    {
    	super.onSaveInstanceState(outState);
    	mController.saveState(getId(), outState);
    }
    
    /**
     * Called from the controller when it needs to identify a view
     * @return The id associated with this View
     */
    @Override
	public int getId()
    {
		return R.layout.smsselector_main_activity_layout;
	}
    
    private Controller mController;
}